package com.example.inventory.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/inventory")
public class InventoryController {

    @GetMapping("/{productId}")
    @PreAuthorize("hasAuthority('SCOPE_inventory.read')")
    public InventoryResponse getInventory(@PathVariable("productId") Long productId) {
        // 模拟数据库查询
        return new InventoryResponse(productId, 100); // 假设商品ID为productId的库存为100
    }
    
    public record InventoryResponse(Long productId, Integer quantity) {}
}
